package com.company.笔试.tx;
/**
 * @Classname MyCircularQueue
 * @Description TODO
 * @Date 2021/9/9 21:11
 * @Created by ylr
 */


public class MyCircularQueue {
    
    public static int max;
    
    public int[] QueueNodes;
    private int front;
    private int rear;

    public MyCircularQueue(int k) {
        max = k ;
        this.QueueNodes = new int[k];
    }


    public int Front(){
        if (this.isEmpty()){
            return -1;
        }

        return QueueNodes[(front+1)%max];
    }


    public int Rear(){

        if (this.isEmpty()){
            return -1;
        }

        return QueueNodes[rear];
    }


    public boolean enQueue(int value){

        if (isFull()){
            return false;
        }
        rear = (rear+1)%max;
        this.QueueNodes[rear] = value;


        return true;
    }


    public boolean deQueue(int value){

        if (isEmpty()){
            return false;
        }
        front = (front+1)%max;
        return true;
    }


    public Boolean isEmpty(){



        return front==rear;
    }

    public Boolean isFull(){


        return (rear+1)%max == front;
    }



}
